﻿@{
    ViewBag.Title = "修改密码";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Header
{
    <script type="text/javascript">
        $(document).ready(function () {
            $.extend($.fn.validatebox.defaults.rules, {
                equals: {
                    validator: function (value, param) {
                        return value == $(param[0]).val();
                    },
                    message: '两个新密码不一致'
                }
            });

            $.extend($.fn.validatebox.defaults.rules, {
                validoldpassword: {
                    validator: function (value, param) {
                        return $('#tips').attr('class') == 'icon-ok';
                    },
                    message: '原密码不匹配'
                }
            });

            var toolbar = [
                {
                    iconCls: 'icon-save',
                    handler: function () {
                        doResetPassword();
                    }
                }];
            $('#pn').panel({ tools: toolbar });

            function doResetPassword() {
                $('#ff').form({
                    url: '/Login/ResetPassword/' + g_guid,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (data) {
                        var msg = $.parseJSON(data);
                        $('ff').form('reset');
                        var msgcontent = '';
                        if (msg.message) {
                            msgcontent = msg.message;
                        } else {
                            msgcontent = msg.success ? '密码修改成功' : '密码修改失败';
                        }
                        $.messager.alert('提示', msgcontent, 'info', function () {
                            $('#tips').hide();
                            $('#tips').attr('class', 'icon-no');
                            $('#ff').form('reset');
                        });
                    }
                });
                $('#ff').submit();
            }
        });

        function doCheckOldPwd(val) {
            if (val && val != '' && val.length > 5) {
                $.ajax({
                    type: "POST",
                    url: "/Login/CheckPassword/" + g_guid,
                    data: "pwd=" + val,
                    success: function (msg) {
                        if (!msg.success) {
                            $('#tips').show();
                            $('#tips').attr('class', 'icon-no');
                            $('#tips').attr('title', '原密码错误');
                        } else {
                            $('#tips').show();
                            $('#tips').attr('class', 'icon-ok');
                            $('#tips').attr('title', '原密码正确');
                        }
                    }
                });
            }
        }
    </script>
}
<div id="pn" class="easyui-panel" title="设置新密码" style="width: 400px;">
    <div style="padding: 10px 10px 0 60px;">
        <form id="ff" method="post">
        <div style="margin: 30px auto; width: 210px;">
            <div style="margin-top: 15px;">
                <label for="oldPwd">
                    原密码：</label>
                <input id="oldPwd" name="oldPwd" onblur="doCheckOldPwd(this.value)" onkeyup="doCheckOldPwd(this.value)"
                    type="password" class="easyui-validatebox" validtype="validoldpassword['crh007@163.com']"
                    data-options="required:true" />
                <div id="tips" class="icon-no" style="width: 16px; height: 16px; float: right; display: none;
                    cursor: pointer;">
                </div>
            </div>
            <div style="margin-top: 15px;">
                <label for="newPwd">
                    新密码：</label>
                <input id="newPwd" name="newPwd" value="" type="password" class="easyui-validatebox"
                    data-options="required:true,validType:'length[6,32]'" />
            </div>
            <div style="margin-top: 15px;">
                <label for="newPwd2">
                    新密码：</label>
                <input name="newPwd2" data-options="required:true" type="password" class="easyui-validatebox"
                    validtype="equals['#newPwd']" />
            </div>
        </div>
        </form>
    </div>
</div>
